package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.Account;
import com.sl.au.entity.User;
import com.sl.au.entity.myMoneyAll;
import com.sl.au.service.ContractService;
import com.sl.au.service.MyMoneyAllService;

@RestController
@RequestMapping(value = "/ui/myMoneyAll")
public class myMoneyAllController extends BaseController {
	
	@Autowired
	MyMoneyAllService mymoneyAllService;
	
	@Autowired
	ContractService contractService;
	
	/**
	 * 费用快速录入页面跳转
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index() {
		ModelAndView modelAndView = this.createLayoutView("myMoney/myMoneyAll");
		Account a = this.getMyAccount();
		String userId = a.getUser().getId();
		String userName = a.getUser().getName();
		String superior = a.getUser().getSaleArea().getSuperior();
		List<User> allSuperiorMen = contractService.getAllSuperiorMenBySuperior(superior);
		List<Object> applyArea = contractService.getAreasBySuperior(superior);
		modelAndView.addObject("allSuperiorMen", allSuperiorMen);
		modelAndView.addObject("applyAreas", applyArea);
		modelAndView.addObject("superior", superior);
		
		return modelAndView;
	}
	
	// 保存其他
		@RequestMapping(value = "/saveMyMoneyAll", method = RequestMethod.POST)
		public Map<String, Object> saveMyMoneyAll(HttpServletRequest request, @RequestBody myMoneyAll mymoneyAll) {
			Map<String, Object> map = new HashMap<String, Object>();
			Account a = this.getMyAccount();
			User user = a.getUser();
			int code = mymoneyAllService.saveMyMoneyAll(mymoneyAll, user);
			map.put("code", code);
			return map;
		}

}
